<?php

class Catalogo
{	
        public function get_detalles_producto($id)
	{
                global $conexion;
		$sql="select * from producto where id='$id'";

                $result = mysql_query($sql,$conexion);

                if(mysql_num_rows($result) == 0)
                    return false;
		
		$prod=array();

                while($reg = mysql_fetch_array($result)){
                    $prod[]=$reg;
                }

		
		return $prod;		
	}

	public static function calcular_items($cart)
	{
		$items=0;
		
		if (is_array($cart))
		{
			$items=array_sum($cart);
		}
		return $items;
	} 
	
	public static function calcular_total($cart)
	{
		$precio=0.0;
	
		if (is_array($cart))
		{
			global $conexion;
			
			foreach ($cart as $id=>$cant)
			{
				$sql="select precio from producto where id='$id'";
				//$result=$conn->query($sql);
                                $result = mysql_query($sql,$conexion);
			
				if ($result)
				{
					//$item=$result->fetch_object();
                                        while ($item = mysql_fetch_object($result)) {
                                            $item_precio=$item->precio;
					
                                            $precio += $item_precio * $cant;
                                        }
				}	
			}
		}
		return $precio;	
	}		
}
?>